package com.yyds.oneservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyds.oneservice.pojo.UserMember;
import com.yyds.oneservice.mapper.UserMemberMapper;
import com.yyds.oneservice.service.IUserMemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyds.oneservice.vo.LoginVo;
import com.yyds.oneservice.vo.PhoneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author lxy
 * @since 2022-12-12
 */
@Service
public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMember> implements IUserMemberService {
    @Autowired
    private UserMemberMapper userMapper;
    @Override
    public UserMember login(LoginVo loginVo) {
        LambdaQueryWrapper<UserMember> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserMember::getUsername,loginVo.getUsername())
                .eq(UserMember::getPassword,loginVo.getPassword());
        return this.getOne(queryWrapper);
    }

    @Override
    public UserMember findUserByphone(String phone) {
        LambdaQueryWrapper<UserMember> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserMember::getPhone, phone );
        if(this.getOne(queryWrapper)==null){
            userMapper.insert(new UserMember().setPhone(phone));
            queryWrapper.eq(UserMember::getPhone, phone );
        }
        return this.getOne(queryWrapper);
    }

    @Override
    public UserMember loginByPhone(PhoneVo phoneVo) {
        LambdaQueryWrapper<UserMember> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserMember::getPhone,phoneVo.getPhone())
                .eq(UserMember::getPassword,phoneVo.getPassword());
        return this.getOne(queryWrapper);
    }
}
